<template>
    <web-view :src="url"></web-view>
</template>

<script>
	import {
		getOrderPayResult
	} from "@/common/api.js";
	export default {
		data() {
			return {
				order_no: '',
				frombiz: '',
				success:0,
				url: null //要打开的外部链接
			}
		},
		onLoad: function(option) {
			this.order_no = option.order_no
			this.frombiz = option.frombiz
			this.url = option.url
		},
		onShow() {
			let that = this
			// setTimeout(function() {
			// 	that.getOrderResult()
			// }, 2000)

			var count = 0;
			var timer = setInterval(function(){
				count++;
				console.log("定时器执行了" + count + "次");
				if(that.success == 1){
					clearInterval(timer);
					if (that.frombiz == 'purchase') {
						uni.navigateTo({
							url: "/stock/payResult?type=0"
						})
					} else {
						uni.navigateTo({
							url: "/goods/payResult?type=0"
						})
					}
				}
				that.getOrderResult();
				if(count >= 5){
					clearInterval(timer);
					console.log("定时器已停止");
				}
			}, 5000);
		},
		methods: {
			getOrderResult() {
				var that = this;
				getOrderPayResult(this, {
					order_no: this.order_no,
					frombiz: this.frombiz
				}, (res) => {
					if (res.code == 200) {
						// if (this.frombiz == 'purchase') {
						// 	uni.navigateTo({
						// 		url: "/stock/payResult?type=0"
						// 	})
						// } else {
						// 	uni.navigateTo({
						// 		url: "/goods/payResult?type=0"
						// 	})
						// }
						that.success = 1;
					}else{
						that.success = 2;
					}
				})
			}
		}
	}
</script>
